<template>
	<view class="patrolDetails_container">
		<view class="" style="height: 160rpx;">
		<view class="mail_List fixed z_ninetynine">
			<view class="mail" style="font-weight: 700;">
				<view class="order">巡检详情</view>
			</view>
		</view>
		<view class="icon fixed z_ninetynine">
			<u-icon name="arrow-left" color="#fefefe" size="40" @click="navigateBack"></u-icon>
		</view>
			
		</view>
		<!-- 执行信息1 -->
		<view class="" v-for="(item,index) in members" :key='index'>
			<view class="data_Statistics" style="padding: 44rpx 24rpx 0 ;" v-show="patrol">
				<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text
					style="font-weight: 700; font-size: 30rpx;">执行信息</text>
			</view>
			<view class="card" style="position: relative; padding: 0 42rpx;" v-show="patrol">
				<u-form :model="form" ref="uForm" >
					<u-form-item label="执行人:">
						<u-input v-model="form.Reporter"
							placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="item.staffName"
							:clearable="false" :disabled="true" />
					</u-form-item>
					<u-form-item label="执行状态:">
								<u-input v-model="form.address"
									placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="待执行"
									:clearable="false" :disabled="true" v-if="particulars.patrolStatus=='1'" />
									<u-input v-model="form.address"
										placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="未接单"
										:clearable="false" :disabled="true" v-if="particulars.patrolStatus=='0'" />
					</u-form-item>
							<image src="/static/workOrder/Group801.png" mode=""
								style=" position: absolute;top: 20rpx; left: 236rpx; width: 280rpx; height: 280rpx;" v-if="particulars.patrolStatus=='1'">
							</image>
							<image src="/static/workOrder/Group804.png" mode=""
								style=" position: absolute;top: 20rpx; left: 236rpx; width: 280rpx; height: 280rpx;" v-if="particulars.patrolStatus=='0'">
							</image>
				</u-form>
			</view>
		</view>
		<!-- 执行信息2 -->
		<view class="data_Statistics" style="padding: 44rpx 24rpx 0 ;">
			<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text
				style="font-weight: 700; font-size: 30rpx;">执行信息</text>
		</view>
		<view class="card" style="position: relative; padding: 0 42rpx;">
			<u-form :model="form" ref="uForm">
				<u-form-item label="执行人:">
					<u-input v-model="form.Reporter"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.staffName"
						:clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="执行状态:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="待接单"
						:clearable="false" :disabled="true" v-if="particulars.patrolStatus=='0'" />
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="待执行"
							:clearable="false" :disabled="true" v-if="particulars.patrolStatus=='1'" />
							<u-input v-model="form.address"
								placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="完成"
								:clearable="false" :disabled="true" v-if="particulars.patrolStatus=='2'" />
								<u-input v-model="form.address"
									placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="超时完成"
									:clearable="false" :disabled="true" v-if="particulars.patrolStatus=='3'" />
				</u-form-item>
				<u-form-item label="接单时间:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="particulars.createTime" :clearable="false" :disabled="true" />
				</u-form-item>
				<image src="/static/workOrder/Group801.png" mode=""
					style=" position: absolute;top: 60rpx; left: 236rpx; width: 280rpx; height: 280rpx;" v-if="particulars.patrolStatus=='1'">
				</image>
				<image src="/static/workOrder/Group689.png" mode=""
					style=" position: absolute;top: 60rpx; left: 236rpx; width: 280rpx; height: 280rpx;" v-if="particulars.patrolStatus=='0'">
				</image>
			</u-form>
		</view>
		<!-- 执行信息 -->
		<view class="order_Allocation" v-if="current==2">
			<view class="data_Statistics" style="padding: 44rpx 24rpx 0 ;">
				<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text
					style="font-weight: 700; font-size: 30rpx;">执行信息</text>
			</view>
				<view class="card" style="padding: 0 42rpx;">
					<u-form :model="form" ref="uForm">
						<u-form-item label="选择执行人:">
	<!-- 						<u-input v-model="form.address"
								placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="周瑜、陆逊"
								:clearable="false" :disabled="true" /> -->
								<u-input v-model="form.title" :custom-style="{'font-weight': '600'}" :disabled="true" :type="newList==''? 'select' : 'text'"
									:select-open="show" placeholder-style="color: #cccccc; text-align: right;"
									:placeholder="newList==''? '请选择执行人' : newList" @click="show = true" />
						</u-form-item>
					</u-form>
					<u-select v-model="show" mode="single-column" :list="list" @confirm="confirm"></u-select>
				</view>
			</view>
		<!-- 巡检信息 -->
		<view class="data_Statistics" style="padding: 28rpx 24rpx 0 ;">
			<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text
				style="font-weight: 700; font-size: 30rpx;">巡检信息</text>
		</view>
		<view class="card" style="padding: 0 42rpx;">
			<u-form :model="form" ref="uForm">
				<u-form-item label="设备名称:">
					<u-input v-model="form.Reporter"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.name"
						:clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="设备编号:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.indexCode"
						:clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="巡检周期:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.cycle"
						:clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="巡检日期:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.InspectionDate"
						:clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="设备地址:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="particulars.deviceAddress" :clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="巡检要点:" label-position="top">
					<u-input v-model="form.describe" placeholder-style="color: #000; text-align: left;"
						:placeholder="particulars.content" :clearable="false" :disabled="true" />
<!-- 					<u-input v-model="form.describe" placeholder-style="color: #000; text-align: left;"
						placeholder="2、访春园区Y32#2单元水表箱处是否清洁干净" :clearable="false" :disabled="true" />
					<u-input v-model="form.describe" placeholder-style="color: #000; text-align: left;"
						placeholder="3、访春园区Y32#2单元水表箱处是否清洁干净" :clearable="false" :disabled="true" /> -->
				</u-form-item>
				<u-form-item label="负责人:">
					<u-input v-model="form.chargeName"
						placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="particulars.chargeName" :clearable="false" :disabled="true" />
				</u-form-item>
				<!-- 巡更点1异常上报 -->
<!-- 					<view class="position" style="display: flex;padding: 10rpx 0 20rpx 31rpx;border-bottom: 1px solid #f6f7f9;" v-if="flag4">
						<text style="color: red;line-height: 70rpx;">异常上报: </text>
						<u-input v-model="form.chargePerson" :custom-style="{'margin-left': '21rpx'}"
							placeholder="请输入异常情况" style="flex: 2;" />
					</view> -->
					<view class="" style="display: flex;justify-content: space-evenly; color: green; padding: 20rpx 0 36rpx;border-bottom: 1px solid #f6f7f9;" v-if="flag4">
						异常
					</view>
					<!-- 巡更点1按钮 -->
					<view class="" style="display: flex;justify-content: space-evenly; padding: 20rpx 0 36rpx; border-bottom: 1px solid #f6f7f9;" v-if="image2==3">
						<u-button type="error" :plain="true" size="mini" shape="circle" @click="reporting4">异常上报</u-button>
						<u-button type="success" size="mini" shape="circle" @click="normal">正常</u-button>
					</view>
					<!-- 巡更点1无异常 -->
					<view class="" style="display: flex;justify-content: space-evenly; color: green; padding: 20rpx 0 36rpx;border-bottom: 1px solid #f6f7f9;" v-if="abnormality3==2">
						正常
					</view>
				<u-form-item label="负责人:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;"
						placeholder="李信" :clearable="false" :disabled="true" />
				</u-form-item>
			</u-form>
		</view>
		<view class="button" v-if="current==1">
			<u-button type="primary" style="flex: 1;" @click="resolved" v-if="image!=3">转交</u-button>
			<u-button type="success" style="flex: 1;" @click="Approved" v-if="image==1">接单</u-button>
			<u-button type="success" style="flex: 1;" @click="implement" v-if="image==2">执行</u-button>
			<u-button type="success" style="flex: 1;" @click="Submit" v-if="image==3">提交</u-button>
		</view>
		<view class="button" v-if="current==2">
			<u-button type="primary" style="flex: 1;" @click="cancel">取消</u-button>
			<u-button type="success" style="flex: 1;" @click="determine">确定</u-button>
		</view>
<!-- 		<u-popup v-model="show" mode="center" width="626rpx" height="430rpx" border-radius="20">
			<view
				style="height: 54rpx; line-height: 54rpx; font-weight: 600; color: #a1a1a1; background-color: #fbfbfb; text-align: center;">
				巡检提示</view>
			<view class="work_Order">
				<view class="work_Order_top"></view>
				<view class="work_Order_bottom" style="margin-top: 10rpx;">巡检完成！</view>
			</view>
		</u-popup> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// form表单
				form: {
					Reporter: '',
					title: '',
					address: '',
					describe: '',
					chargePerson: '',
					Executor: '',
					Maintenance: '',
					end: '',
					// 手机号码
					staffPhone:''
				},
				// 演示地址，请勿直接使用
				action: 'http://www.example.com/upload',
				current: 1,
				show: false,
				image:1,
				image2:1,
				flag4:false,
				abnormality3:1,
				list: [{
						value: '1',
						label: '江'
					},
					{
						value: '2',
						label: '湖'
					}
				],
				show3: false,
				show2: false,
				newList: '', 
				// 已完成Id
				patrolId:'',
				// 车辆详情
				particulars:'',
				// 审核通过
				staff:'',
				// 执行信息1的数据
				members:'',
				// 控制执行信息1的显示与隐藏
				patrol:false
			}
		},
		onLoad(val) {
			this.loginId = uni.getStorageSync("setModel")
			console.log(val)
			if(val.patrolId){
			this.patrolId=val.patrolId
				// 已完成详情
				this.getListVehicleByIds()
			}
			// this.loading()
		},
		methods: {
			// 已完成详情
			getListVehicleByIds() {
				this.$http.get('Patrol/ExaminePatrol',{patrolId:this.patrolId}).then(res => {
					this.particulars=res.data.patrol
					let patrolMembers=res.data.patrolMembers
					if(patrolMembers.length!=0) {
						this.members= patrolMembers
						this.patrol=true
					}
					console.log(res, '待接单详情')
					// this.owners = res.data
				})
			},
			// 点击转交按钮
			resolved() {
				this.current = 2
				this.$http.get('WorkOrder/getStaff',{deptId:this.loginId.deptId}).then(res => {
					console.log(res,'执行人')
					// this.particulars=res.data
					let lists = res.data
					this.list= this.changeKey (lists, ['value', 'label','staffPhone']);
				})
			},
			// 注意返回值为一个数组，单列时取数组的第一个元素即可(只有一个元素)
			confirm(e) {
				// console.log(e);
				let sign = ''
				e.forEach((item,index) => {
					this.sign =item.value
					this.form.title=item.label
						// console.log(item.label);
						// console.log(this.sign);
				   })
				this.list.forEach((item,index)=>{
					if(item.value==this.sign) {
						console.log(item.staffPhone)
						this.form.staffPhone=item.staffPhone
					}
				})
				// console.log(e-'1')
				// let abc = this.list[e-'1'].staffPhone
				// console.log(abc)
			},
			cancel() {
				this.current = 1
			},
			// 点击确定
			determine() {
				this.show2 = true
				// console.log(171)
				this.$http.get('Patrol/insertUpdateForward',{
					phone:this.form.staffPhone,
					patrolId:this.patrolId
				}).then(res => {
					console.log(res,'工单转交')
					// this.particulars=res.data
				})
				setTimeout(function() {
					uni.navigateBack()
				}, 1000);
			},
			changeKey (lists, key) {
						            let newArr = [];
						            lists.forEach((item) => {
						                let newObj = {};
						                for (var i = 0; i < key.length; i++) {
						                newObj[key[i]] = item[Object.keys(item)[i]]
						                }
						                newArr.push(newObj);
						            })
						                return newArr;
			 },
			// 接单
			Approved() {
				this.image = 2
				// 巡检工单接单
				this.$http.put('Patrol/updatePatrolById',{patrolId:this.patrolId}).then(res => {
					console.log(res,'接单')
					// this.particulars=res.data
				})
			},
			// 执行
			implement() {
				this.image=3
				this.image2 = 3
			},
			// 提交
			Submit() {
				if(this.form.chargePerson!=''||this.abnormality3==2) {
					this.show=true
				}
				// 巡检工单提交
				this.$http.put('PatrolStatus/updatePatrolOrderStatusSuccess',{orderId:this.orderId}).then(res => {
					console.log(res,'巡检工单提交')
					// this.particulars=res.data
					uni.navigateBack()
				})
			},
			// 异常上报
			reporting4() {
				// 巡检工单异常上报
				this.$http.put('PatrolStatus/updatePatrolOrdertReport',{orderId:this.orderId}).then(res => {
					console.log(res,'巡检工单异常上报')
					// this.particulars=res.data
				})
				this.flag4=true
				this.image2 = 1
			},
			// 正常按钮
			normal() {
				this.abnormality3=2
				this.image2 = 1
			}
		}
	}
</script>

<style lang="scss" scoped>
	.patrolDetails_container {
		.mail_List {
			overflow: hidden;
			width: 100%;
			background-color: #f2f2f2;

			.mail {
				padding: 10rpx 0;
				// margin-top: 96rpx;
				color: #999999;
				font-size: 40rpx;
				background-color: #e5e5e5;
			}

			.order {
				text-align: center;
			}
		}

		/deep/.card {
			.u-form-item--left {
				flex: unset !important;
				width: unset !important;
			}

			.frequency {
				display: flex;

				// justify-content: space-between;
				u-input {
					flex: 2;
				}
			}

			.example {
				display: flex;
				margin-left: 67rpx;
			}

			.u-form-item--right {
				margin-left: 31rpx;
			}
			
			button {
				width: 170rpx;
				border-radius: 100rpx!important;
			}
		}
		
		.order_Allocation {
			/deep/.card {
				u-form-item {
					.u-input {
						input {
							text-align: right!important;
						}
						
					}
				}	
			}
		}

		.icon {
			position: absolute;
			top: 18rpx;
			// top: 114rpx;
			left: 20rpx;
		}

		.second_card {
			.u-cell {
				padding: 18rpx 32rpx;

				/deep/.u-cell__value {
					color: #333333;
					font-weight: 600;
				}
			}

			/deep/.uni-card__content {
				padding: 16rpx 24rpx;
			}
		}

		/deep/button {
			border-radius: unset !important;
		}

		.uni-border[data-v-19622063]:after {
			border: unset;
		}

		/deep/.uni-border.data-v-19622063:after {
			border: unset;
		}

		.slot-btn__hover {
			background-color: rgb(235, 236, 238);
		}

		.button {
			display: flex;
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			// margin-top: 200rpx;
			border-radius: 14rpx;
			overflow: hidden;
			z-index: 9;

			.u-btn {
				border-radius: unset;
			}
		}

		.work_Order {
			margin-top: 60rpx;
			text-align: center;

			.work_Order_top {
				width: 168rpx;
				height: 168rpx;
				margin: 0 auto;
				background-color: #e5e5e5;
				border-radius: 50%;
			}
		}
	}
</style>
